package com.servlet;

import com.entity.Blog;
import com.service.BlogService;
import com.service.BlogServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "BlogListServlet",urlPatterns = {"/BlogListServlet"},
		initParams = {@WebInitParam(name = "classname",value = "T328")})
public class BlogListServlet extends HttpServlet {

	@Override
	public void init() throws ServletException {
		super.init();
		System.out.println(getServletConfig().getInitParameter("classname"));//servlet的初始化参数==》当前servlet中

		System.out.println(getServletContext().getInitParameter("version")); //上下文初始化参数==》整个web应用程序中
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//1、获取用户请求==》参数==》条件
		//2、操作
		BlogService blogService = new BlogServiceImpl();
		List<Blog> list = blogService.findAll();
		//3、页面跳转==>传递数据==》转发
		request.setAttribute("list", list);
		request.getRequestDispatcher("show.jsp").forward(request, response);

	}
}
